import { createSlice } from '@reduxjs/toolkit';
import { devInfoChangeCreator } from '@ray-js/tuya-dp-kit';
import { DpState, DpStateKey } from './dpStateSlice';

export type DpValue = boolean | number | string;

type ReduxDevInfo = DevInfo & {
  schema: Record<DpStateKey, any>;
  state: DpState;
  dpIdCodeMap: Record<number, DpStateKey>;
  dpCodeIdMap: Record<DpStateKey, number>;
};

/**
 * ExtraActions
 */
export const devInfoChange = devInfoChangeCreator<ReduxDevInfo>();

/**
 * Slice
 */
const devInfoSlice = createSlice({
  name: 'devInfo',
  initialState: {} as ReduxDevInfo,
  reducers: {},
  extraReducers: builder => {
    builder.addCase(devInfoChange, (state, action) => {
      return {
        ...state,
        ...action.payload,
      };
    });
  },
});

export default devInfoSlice.reducer;
